<template>
	<view>
		<tt-bar title="核销体验码" leftIcon="icon-back"></tt-bar>
		<view class="inputBox">
			<view class="inputGroup">
				<input type="text" placeholder="请输入核销码" v-model="code" />
				<!-- <text class="iconfont icon-scan" @tap="saoma"></text> -->
			</view>
			<button class="wObtn" @tap="getData">确认核销</button>
		</view>
	</view>
</template>

<script>
	import {mapState} from "vuex";
	import ttBar from "@/components/ttBar/ttBar.vue";
	import API from "@/common/api.js";
	export default {
		computed:{
			...mapState({
				userInfo:state=>state.user.userInfo,
				settledProgress:state=>state.settled.settledProgress,
				selectShop:state=>state.shop.selectShop
			})
		},
		components:{ttBar},
		data() {
			return {
				code:''
			};
		},
		methods:{
			getData(){
				API.validCode({
					storeId:this.selectShop.id,
					code:this.code
				}).then(res=>{
					if(res.data.code==1){
						uni.showToast({
							title: '核销成功',
							icon: 'none'
						});
					}else{
						uni.showToast({
							title: '核销失败，'+res.data.msg,
							icon: 'none'
						});
					}
					
				})
			},
			saoma(){
				COMM.scanCode().then(res=>{
					console.log(res);
					this.code=res.scanCode
					this.getData()
				})
			},
		},
		onLoad(cfm) {
			this.code=cfm.scanCode
			// this.getData()
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1500)
		}
	}
</script>

<style lang="less">
	page{
		background-color: #f6f6f6;
	}
	.inputBox{
		padding: 30upx 20upx;
		.inputGroup{
			display: flex;
			background-color: #FFFFFF;
			height: 90upx;
			border-radius: 10upx;
			align-items: center;
			padding: 0 20upx;
			margin-bottom: 30upx;
			input{
				height: 86upx;
				line-height: 86upx;
				font-size: 32upx;
				flex: 1;
			}
			.iconfont{
				font-size: 40upx;
				color: #666666;
			}
		}

		button {
			height: 88upx;
			background-color: #ffb423;
			border-radius: 44upx;
			line-height: 88upx;
			width: 100%;
			color: #FFFFFF;
			margin-top: 50upx;
			margin-bottom: 38upx;
		}
		
		button:after {
			border: none;
		}
	}
</style>
